package com.zzh.jetpackdemo.live.community

import android.util.Log
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.OnLifecycleEvent
import org.jetbrains.annotations.NotNull

/**
 * @author zhangzhihao
 * @email zhangzhihao@gongjiangren.net
 * @date 2020-08-20
 * @desc
 */
class MyFragObserver (var tag: String) : LifecycleObserver {

    @OnLifecycleEvent(Lifecycle.Event.ON_CREATE)
    fun onCreate(
        @NotNull owner: LifecycleOwner
    ) {
        Log.i("zhangzhihao", ">frag>>onCreate>>$tag")
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
    fun onResume(
        @NotNull owner: LifecycleOwner
    ) {
        Log.i("zhangzhihao", ">frag>>onResume>>$tag")
    }

//    @OnLifecycleEvent(Lifecycle.Event.ON_ANY)
//    fun onAny(
//        @NotNull owner: LifecycleOwner,
//        @NotNull event: Lifecycle.Event
//    ) {
//        Log.i("zhangzhihao", ">${event.name}>frag>onAny>>$tag")
//    }

    @OnLifecycleEvent(Lifecycle.Event.ON_START)
    fun onStart(
        @NotNull owner: LifecycleOwner
    ) {
        Log.i("zhangzhihao", ">frag>>onStart>>$tag")
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
    fun onPause(
        @NotNull owner: LifecycleOwner
    ) {
        Log.i("zhangzhihao", ">frag>>onPause>>$tag")
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_STOP)
    fun onStop(
        @NotNull owner: LifecycleOwner
    ) {
        Log.i("zhangzhihao", ">frag>>onStop>>$tag")
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
    fun onDestroy(
        @NotNull owner: LifecycleOwner
    ) {
        Log.i("zhangzhihao", ">frag>>onDestroy>>$tag")
    }

}